package myThread;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;

class MyThread{
    private BlockingQueue<Runnable> queue = null;
    public MyThread(int n){
        queue = new LinkedBlockingDeque<>(1000);
        for (int i = 0; i < 4; i++) {
            Thread t = new Thread(()->{
                while(true){
                    Runnable task = null;
                    try {
                        task = queue.take();
                        task.run();

                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });
            t.start();
        }
    }
    public void submit(Runnable task) throws InterruptedException {
        queue.put(task);
    }
}
public class demo33 {
    public static void main(String[] args) throws InterruptedException {
        MyThread pool = new MyThread(4);
        for (int i = 0; i < 1000; i++) {
            pool.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println(Thread.currentThread().getName()+"hello");
                }
            });
        }
    }
}
